package com.coding.serivce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

/**
 * -- Created by IntelliJ IDEA.
 * -- REMARK:
 * -- User: tanwei
 * -- Date: 2020/7/5
 * -- Time: 1:27 下午
 * --
 */
@Service
public class EmialSerice {

    @Autowired
    JavaMailSenderImpl javaMailSender;


    public void senMail() {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("通知");
        message.setText("您好，你以中奖领取地址：http://www.cwl.gov.cn/。如有疑问联系客服。");
        message.setFrom("634473715@qq.com");
        message.setTo("578389519@qq.com");
        javaMailSender.send(message);
        System.out.println("通知成功！");
    }



    public void senMailPuls() throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        //基本信息
        helper.setSubject("复杂的邮件测试");
        helper.setText("<h1 style='color:red'>  今天</h1>");
        // 发送附件
        helper.addAttachment("1.jpg",new File(""));
        helper.setTo("578389519@qq.com");
        helper.setFrom("634473715@qq.com");
        javaMailSender.send(mimeMessage);
    }
}
